// 简单工厂（TypeScript 版本）

// 简单工厂（TypeScript 版本）
// ====== 订单相关 ======
export type OrderType = '餐饮' | '生鲜' | '鲜花';

export interface OrderExtra {
	// 可以包含不同订单类型的个性字段
	tasteNote?: string;
	freshReq?: string;
	flowerReq?: string;
}

export interface Order {
	orderId: string;
	phone: string;
	address: string;
	extra: OrderExtra | null;
}

export function createOrder(
	orderId: string,
	phone: string,
	address: string,
	orderType: OrderType,
	extraInfo: string
): Order {
	let extra: OrderExtra | null = null;
	switch (orderType) {
		case '餐饮':
			extra = { tasteNote: extraInfo };
			break;
		case '生鲜':
			extra = { freshReq: extraInfo };
			break;
		case '鲜花':
			extra = { flowerReq: extraInfo };
			break;
	}
	return { orderId, phone, address, extra };
}

// ====== 文档相关 ======
export type DocType = 'Word' | 'Excel' | 'PPT';

export interface DocumentSpec {
	wordCount?: number;
	rowCount?: number;
	slideCount?: number;
}

export interface Document {
	docName: string;
	author: string;
	createTime: string;
	spec: DocumentSpec | null;
}

export function createDocument(
	docName: string,
	author: string,
	docType: DocType,
	specValue: number
): Document {
	const createTime = new Date().toLocaleString();
	let spec: DocumentSpec | null = null;
	switch (docType) {
		case 'Word':
			spec = { wordCount: specValue };
			break;
		case 'Excel':
			spec = { rowCount: specValue };
			break;
		case 'PPT':
			spec = { slideCount: specValue };
			break;
	}
	return { docName, author, createTime, spec };
}

// ====== Demo ======
export function demoOrderAndDocument(): void {
	const foodOrder = createOrder('123456', '13800138000', 'XX小区1号楼', '餐饮', '少辣、多放醋');
	const freshOrder = createOrder('654321', '13900139000', 'YY小区3号楼', '生鲜', '冷藏配送、避免挤压');
	const flowerOrder = createOrder('987654', '13700137000', 'ZZ小区5号楼', '鲜花', '生日花');

	console.log(foodOrder);
	console.log(freshOrder);
	console.log(flowerOrder);

	const reportDoc = createDocument('季度报告', '张三', 'Word', 2500);
	const dataSheet = createDocument('销售数据', '李四', 'Excel', 120);

	console.log(reportDoc);
	console.log(dataSheet);
}

// 如果直接运行这个文件，打印 demo
demoOrderAndDocument();

